package com.springapp.mvc.util;

import com.springapp.mvc.services.CustomUser;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

/**
 * Created by dbychkov on 30.12.2014.
 */
public class SecurityUtils {

    public static CustomUser getCurrentUser(){
        try {
            Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
            return (CustomUser) authentication.getPrincipal();
        }catch (Exception e){
            return null;
        }
    }

    public static Long getCurrentUserId(){
        try{
            return getCurrentUser().getUserId();
        } catch(Exception e){
            return null;
        }

    }


}
